// var obj = $("#main .center");
// $("img").mouseenter(function() {
// 	console.log("width : " + obj.width());
// 	console.log("height: " + obj.height());
// 	console.log("top   : " + obj.offset().top);
// 	console.log("left  : " + obj.offset().left);
// });

var bulid_date = new Date(2021, 11, 11); //12月11日开始
builddate();
dt();
setInterval(builddate, 2000);
setInterval(dt,500);

function builddate() {
	var now = new Date();
	var year = now.getFullYear();
	var build_days = parseInt((now.getTime() - bulid_date.getTime()) / 86400000);
	var past_days = (now.getTime() - new Date(year, 1, 1).getTime()) / 86400000;
	var remaining_days = parseInt((isLeapYear(year) ? 366 : 365) - past_days);
	var nowmil = now.getTime();
	var birthday = new Date(year, 9, 25).getTime();
	var nextbirthday = new Date(year + 1, 9, 25).getTime();
	$(".date1").html("小站已经建立了" + build_days + "天");
	$(".date2").html(year + "年度还剩余" + remaining_days + "天");
	if (nowmil < birthday) {
		var birthdays = parseInt((birthday - nowmil) / 86400000);
		$(".date3").html("距离生日还有" + birthdays + "天");
	} else if (birthday <= nowmil && nowmil < (birthday + 86400000)) {
		$(".date3").html("Happy birthday!");
	} else {
		var birthdays = parseInt((nextbirthday - nowmil) / 86400000);
		$(".date3").html("距离生日还有" + birthdays + "天");
	}
}

function isLeapYear(year) {
	return (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) ? true : false;
}

function dt() {
	var myDate = new Date;
	var year = myDate.getFullYear(); //获取当前年
	var month = myDate.getMonth() + 1; //获取当前月
	var day = myDate.getDate(); //获取当前日
	var hour = myDate.getHours(); //获取当前小时数(0-23)
	var minute = myDate.getMinutes(); //获取当前分钟数(0-59)
	var second = myDate.getSeconds(); //获取当前秒
	var week = myDate.getDay();
	var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
	var date = year + "年" + parseInt(month / 10) + "" + month % 10 + "月" + parseInt(day / 10) + "" + day % 10 + "日";
	// date += weeks[week];
	var time = parseInt(hour / 10) + "" + hour % 10 + ":";
	time += parseInt(minute / 10) + "" + minute % 10 + ":";
	time += parseInt(second / 10) + "" + second % 10;
	$(".date").html(date);
	$(".time").html(time);
}

var prev = $("#lunbo .btn li.prev");
var next = $("#lunbo .btn li.next");
var pics = $("#lunbo .pics li");
var pics_nav = $("#lunbo .pic_nav li");
var pic_length = pics.length;
var setId = null;

init();

function init() {
	pics.eq(0).fadeIn().siblings().fadeOut();
	setId = setInterval(lunbo, 3000);
}
var curIndex = 0;

function change(index) {
	pics.eq(index).fadeIn().siblings().fadeOut();
	pics_nav.eq(index).addClass("on").siblings().removeClass("on");
}

next.click(function() {
	let index = (++curIndex) % pic_length;
	change(index);
});

prev.click(function() {
	let index = (--curIndex) % pic_length;
	change(index);
});

pics_nav.click(function() {
	curIndex = $(this).index();
	change(curIndex);
});

function lunbo() {
	let index = (++curIndex) % pic_length;
	change(index);
}

$("#lunbo").mouseenter(function() {
	clearInterval(setId);
	$("#lunbo .btn li").show();
	$("#lunbo .pic_nav").css("display", "flex");

});

$("#lunbo").mouseleave(function() {
	setId = setInterval(lunbo, 3000);
	$("#lunbo .btn li").hide();
	$("#lunbo .pic_nav").css("display", "none");
});
